package com.CTAtracker.android.Models;

import java.text.DecimalFormat;
import java.util.ArrayList;

public class AroundStation extends Station implements Comparable<Double> {

	private ArrayList<ColorStation> _listColorStation;
	
	private double _distance; 
	
	public AroundStation(Station s){
		super(s);
		_distance = 0; 
		_listColorStation = new ArrayList<ColorStation>();
	}
	
	public AroundStation(Station s, double distance, ArrayList<ColorStation> listColorStation){
		super(s); 
		_distance = distance; 
		_listColorStation = listColorStation;
	}
	
	/**
	 * Compare the current closest station to another station and add it if necessary 
	 * @param finalListStation the current list of the closest station 
	 * @param station the station to compare with 
	 * @param pos the position of the user
	 */
	public void iscloser(ArrayList<AroundStation> finalListStation, Position pos) {
		for(int i=0; i<finalListStation.size(); i++){
			if (_distance < finalListStation.get(i).getDistance()){
				finalListStation.remove(i); 
				finalListStation.add(this);
				return;
			}
		}
	}
	
	public void setDistance(double distance){
		_distance = distance;
	}
	
	public String distanceToString(){
		
		if (_distance < 1 ){
			DecimalFormat df = new DecimalFormat("@@##");
			return df.format(_distance*1000)+" m";
		}else {
			DecimalFormat df = new DecimalFormat("@##");
			return df.format(_distance) + " Km";
		}
	}
	
	public double getDistance(){
		return _distance;
	}
	
	public ArrayList<ColorStation> getListColorStation(){
		return _listColorStation;
	}
	
	public void addColor(ColorStation c){
		_listColorStation.add(c);
	}
	
	public void addColor(ArrayList<ColorStation> list){
		_listColorStation.addAll(list);
	}

	public int compareTo(AroundStation station){
		return compareTo(station.getDistance());
	}
	
	@Override
	public int compareTo(Double another) {
		if (another == _distance)
			return 0;
		if (_distance > another)
			return 1; 
		else 
			return -1;
	}
}
